namespace( "org.jaxson.util" );

/**
 * Ensures only 1 function will execute in the scope of
 * a single Timeout object.
 */
org.jaxson.util.Timeout = function( func, delay ){
	
	var id = -1;
	var wrapper = function(){
		return func( arguments );
	};

	return{
		getId : function(){ 
			return id; 
		},
		setDelay : function( t ){
			delay = t;
		},
		start: function(){
			clearTimeout( id );
			id = setTimeout( wrapper, delay );
			return id;
		},
		stop: function(){
			clearTimeout(id);
			id = -1;
		},
		setFunction: function( func ){
			this.stop();
			wrapper = function(){
				func(arguments);
			}
			this.start();
			return id;
		}
	}
};
